package tpoo.common.utils.codec;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XStreamCodec implements Codec {	
	
	private XStream xstream = new XStream(new DomDriver());
	
	public void code(Object object, OutputStream out) {
		OutputStreamWriter ow = new OutputStreamWriter(out);
		xstream.toXML(object, ow);
	}

	public Object decode(InputStream in) {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(in));
		return xstream.fromXML(br);
	}

	public String getDescription() {
		return "Xstream codec implementation";
	}

	

}
